#!/usr/bin/env python
#-*- coding: utf-8 -*-

def _gcd_double(a, b):
    if(a < b):
        a, b = b, a
    if 0 == b:
        return a
    if a%2==0 and b%2==0:
        return 2*_gcd_double(a/2, b/2)
    if a%2 == 0:
        return _gcd_double(a/2, b)
    if b%2 == 0:
        return _gcd_double(a, b/2)
    return _gcd_double((a+b)/2, (a-b)/2)

'''
取多个数值的最大公约数
arr:数组或元组
'''
def gcd(arr):
    if len(arr) <= 0:
        return 0
    last = arr[0]
    for item in arr:
        last = _gcd_double(last, item)
        if(1 == last):
            return 1
    return last
